<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 商品折扣后的最终价格 -->
    <script>
      var finalPrices = function (prices) {
        const arr = []
        for (let i = 0; i < prices.length; i++) {
          for (let j = i + 1; j < prices.length; j++) {
            // 比较之后有折扣
            if (prices[j] <= prices[i]) {
              arr.push(prices[i] - prices[j])
              break
            }
            // 比较之后无折扣
            if (j === prices.length - 1) {
              arr.push(prices[i])
            }
          }
          // 最后一个肯定没有折扣
          if (i === prices.length - 1) {
            arr.push(prices[i])
          }
        }
        return arr
      }
      console.log(finalPrices([8, 4, 6, 2, 3]))
    </script>
  </body>
</html>
